package agent;

import java.util.ArrayList;

import operations.Operation;

public class Node {
	private Node parent;
	private ArrayList<Node> children;
	private int layer;
	
	private State state;
	
	public Node(Node parent,State state,int layer) {
		children=new ArrayList<Node>();
		this.parent=parent;
		this.state=state;
		this.layer=layer;
	}
	
	public void expand(){
		State s;
		for (Operation o : Agent.operationQue) {
			if ((s = o.exec(state))!=null && !Agent.getInstance().alreadyExpanded(s) ){
				children.add(new Node(this,s,layer+1));
			}
		}
	}

	public ArrayList<Node> getChildren() {
		return children;
	}
	
	@Override
	public String toString() {
		return state.toString()+"     "+getLayer();
	}
	
	public State getState(){
		return state;
	}
	public int getLayer(){
		return this.layer;
	}
	public Node getParent(){
		return this.parent;
	}
	
}
